<?php


define('DOCROOT', '/var/www/advancelab/chilik2/');
define('DS', DIRECTORY_SEPARATOR);

//require_once DOCROOT.'libs'.DS.'simpletest'.DS.'autorun.php';

define('TESTROOT', DOCROOT);
define('TDS', DS);

require_once DOCROOT.'libs'.DS.'chilik'.DS.'entity'.DS.'tester'.DS.'entity.regressiontest.php';

require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'abstraction'.DS.'abstraction.requestparser.php';

require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'entity'.DS.'entity.requestaccept.php';
require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'entity'.DS.'entity.requestuseragent.php';
require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'entity'.DS.'entity.requestfile.php';
require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'entity'.DS.'entity.requestcookie.php';

require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'core.requestparser.php';
require_once DOCROOT.'libs'.DS.'chilik'.DS.'core'.DS.'request'.DS.'core.mvcrequest.php';


date_default_timezone_set('Asia/Jakarta');

class TrialTest extends Entity\RegressionTest
{
    function __construct()
    {
        $basePath = DOCROOT.'unittest/request/testfiles';
        
        $this->readDirRecursively( $basePath, 'data' );
        $this->files = $this->total;
        
        parent::__construct();
    }
    
    function runRegressionTest( $name )
    {
        include $name;
        
        echo $name,"\n";
        
        $_SERVER = $server;
        $_FILES  = $files;
        $_REQUEST = $request;
        $_COOKIE = $cookies;
        
        $requestParser = new Core\RequestParser();
        $req = $requestParser->createRequest();
        
        $expectedFileName = $name . '.exp';
        
        if ( !file_exists( $expectedFileName ) )
        {
            file_put_contents( $expectedFileName, serialize( $req ) );
            
        }
        else
        {
            $expected = unserialize(file_get_contents( $expectedFileName ));
            
            if( $expected !== $req ) echo __FILE__,": problem detected !\n";
        }
        
    }
}

echo "<pre>";

$test = new TrialTest;
foreach($test->getFiles() as $key => $file)
{
    $test->setCurrentFile($file['file']);
    $test->runTest();
}

print_r($test);

echo "</pre>";
